<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>客户端</title>
</head>
<body>
	<form action="" onsubmit="return false;"> 
		<textarea id="message" rows="" cols="" style="width:400px;height: 300px;"></textarea>
		<input type="button" value="发送数据" onclick="send(this.form.message.value);"/> 
		<h3> 服务端输出 ： </h3>
		<textarea id="responseText" rows="" cols="" style="width:400px;height: 300px;"></textarea>
		
		<input  type="button" value="清空内容" 
		onclick="javascript:document.getElementById('responseText').value=''" />
	</form>
	<script type="text/javascript">
		var socket =new WebSocket("ws://localhost:8899/wss")
		
		socket.onmessage=function(e){
			var ta = document.getElementById('responseText');
			ta.value=ta.value + "\n" + e.data;
		}
		
		socket.onopen=function(e){
			var ta = document.getElementById('responseText');
			ta.value='连接开启';
		}
		
		socket.onclose=function(e){
			var ta = document.getElementById('responseText');
			ta.value=tta.value +'\n' +'连接关闭';
		}
		
	function send(message){
		if(socket.readyState == WebSocket.OPEN){
			socket.send(message)
		}else{
			alert('连接尚未开启');
		}
	}
	</script>
</body>
</html>